package com.neuedu.helloworld.controller;//package com.neuedu.helloworld.controller;


import com.neuedu.helloworld.entity.User;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {


    /**
     * http://localhost/save?id=100&name=1231
     * @param user
     * @return
     */
    @RequestMapping("/save")
    public User save(@Validated  User user, BindingResult br){

        //保存到数据库中
        System.out.println(user);


        //暂时打印错误消息到控制台， 应该抛出到页面
        if(br.getAllErrors().size() > 0) {

            for (ObjectError allError : br.getAllErrors()) {
                System.out.println("allError.getDefaultMessage() = " + allError.getDefaultMessage());
            }

        }


        return user;

    }



}
